import os

import mmcv
# using a pre-trained detector. 预训练配置
from mmcv import Config


# root_path=r"/project/train/src_repo/mmdetection/" # 要改的

root_path=r"/home/deepin/Documents/ji_pingtai/mmdetection/" # 要改的

cfg_path=root_path+'work_dir/swin_cfgformat2.py'

cfg = Config.fromfile(cfg_path)


#训练----------------------------------------------------
from mmdet.datasets import build_dataset
from mmdet.models import build_detector
from mmdet.apis import train_detector


# Build dataset 构建 数据集
datasets = [build_dataset(cfg.data.train)]

# Build the detector 构建 识别
model = build_detector(cfg.model)

# Add an attribute for visualization convenience 添加属性以方便可视化，模型的类别
model.CLASSES = datasets[0].CLASSES

# Create work_dir 文件夹
mmcv.mkdir_or_exist(os.path.abspath(cfg.work_dir))


train_detector(model, datasets, cfg, distributed=False, validate=True) # -------进行----训练-----


# # # 查看 评估结果 load tensorboard in colab
# # %load_ext tensorboard
# #
# # # see curves in tensorboard
# # tensorboard --logdir ./tutorial_exps  #--------运行这个看看 数的 曲线



